package pl.flight2013.entity; 

import java.io.Serializable;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Version;

@Entity
@Table(name = "klient")
public class Klient implements Serializable {

	private static final long serialVersionUID = 1L;
	@Id
	private @GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = "id", updatable = false, nullable = false)
	Long id = null;
	@Version
	private @Column(name = "version")
	int version = 0;

	@Column
	private String imie;

	@Column
	private String nazwisko;

	@Column
	private String miasto;

	@Column
	private String ulica;

	@Column
	private String email;
	
	@Column
	private String nrdomu;
	
	@Column
	private String nrlok;
	
	@Column
	private String poczta;
	

	@OneToOne(cascade = CascadeType.ALL, optional=false)
	private Users users = new Users();

	public Long getId() {
		return this.id;
	}

	public void setId(final Long id) {
		this.id = id;
	}

	public int getVersion() {
		return this.version;
	}

	public void setVersion(final int version) {
		this.version = version;
	}

	@Override
	public boolean equals(Object that) {
		if (this == that) {
			return true;
		}
		if (that == null) {
			return false;
		}
		if (getClass() != that.getClass()) {
			return false;
		}
		if (id != null) {
			return id.equals(((Klient) that).id);
		}
		return super.equals(that);
	}

	@Override
	public int hashCode() {
		if (id != null) {
			return id.hashCode();
		}
		return super.hashCode();
	}

	public String getImie() {
		return this.imie;
	}

	public void setImie(final String imie) {
		this.imie = imie;
	}

	public String getNazwisko() {
		return this.nazwisko;
	}

	public void setNazwisko(final String nazwisko) {
		this.nazwisko = nazwisko;
	}

	public String getMiasto() {
		return this.miasto;
	}

	public void setMiasto(final String miasto) {
		this.miasto = miasto;
	}

	public String getUlica() {
		return this.ulica;
	}

	public void setUlica(final String ulica) {
		this.ulica = ulica;
	}

	public String getEmail() {
		return this.email;
	}

	public void setEmail(final String email) {
		this.email = email;
	}

	public Users getUsers() {
		return this.users;
	}

	public void setUsers(final Users users) {
		this.users = users;
	}

	public String toString() {
		String result = "";
		if (imie != null && !imie.trim().isEmpty())
			result += imie;
		if (nazwisko != null && !nazwisko.trim().isEmpty())
			result += " " + nazwisko;
		if (miasto != null && !miasto.trim().isEmpty())
			result += " " + miasto;
		if (ulica != null && !ulica.trim().isEmpty())
			result += " " + ulica;
		if (email != null && !email.trim().isEmpty())
			result += " " + email;
		return result;
	}

	public void newUsers() {
		this.users = new Users();
	}

	public String getNrdomu() {
		return nrdomu;
	}

	public void setNrdomu(String nrdomu) {
		this.nrdomu = nrdomu;
	}

	public String getNrlok() {
		return nrlok;
	}

	public void setNrlok(String nrlok) {
		this.nrlok = nrlok;
	}

	public String getPoczta() {
		return poczta;
	}

	public void setPoczta(String poczta) {
		this.poczta = poczta;
	}
}